package com.aaa.service.Impl;

import cn.hutool.core.date.DateUtil;
import com.aaa.entity.Playlist;
import com.aaa.entity.Singer;
import com.aaa.mapper.MelodyMapper;
import com.aaa.mapper.PlaylistMapper;
import com.aaa.mapper.SingerMapper;
import com.aaa.service.PlaylistService;
import com.aaa.service.SingerService;
import com.aaa.util.SingerPageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class PlaylistServiceimpl implements PlaylistService {

    @Resource
    private PlaylistMapper playlistMapper;
    @Resource
    private MelodyMapper melodyMapper;
    @Override
    public SingerPageInfo<Playlist> listAll(Integer pagesize, Integer currentpage, String inputm) {
        //        当前页
        Integer page=(currentpage-1)*pagesize;
        //        尾页
        Integer count = playlistMapper.counts(inputm);
        List<Playlist> select = playlistMapper.listAll(page, pagesize,inputm);
        for (Playlist sele:select){
            Integer pid = sele.getPid();
            Integer geselect = melodyMapper.geselect(pid);
            sele.setCounts(geselect);
        }
        SingerPageInfo pageInfo=new SingerPageInfo();
        pageInfo.setCountpage(currentpage);
        pageInfo.setWeipage(count);
        pageInfo.setBooks(select);
        return pageInfo;
    }

    @Override
    public Integer update(Playlist playlist) {
        return playlistMapper.update(playlist);
    }

}
